package com.erp.print.controller;

import com.erp.print.service.PrintsService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;

/**
 * @author moluwangling
 * @version 2024/11/18 21:09
 * @className print
 * @description 服务打印
 **/
@RestController
@RequestMapping("/erp/print")
public class print {
    @Resource
    private PrintsService printService;

    @PostMapping("")
    public void savePrint(HttpServletRequest request, HttpServletResponse response) {
        String fileName = request.getParameter("fileName");
        String fileFullPath = "C:/code/" + fileName;

        InputStream input = null;
        FileOutputStream fos = null;
        try {
            input = request.getInputStream();
            printService.print(input, fileName);
        } catch (Exception ignored) {

        }
    }
    @PostMapping("/config")
    public void config(@RequestBody Map<String,Object> data, HttpServletResponse response) {
        printService.config(data);

    }
    @PostMapping("/PrintService")
    public Set<String> PrintService() {
        printService.selectPrintService();
      return printService.serviceMap.keySet();
    }

    @PostMapping("test")
    public String test(@RequestBody String string) {
        return "hoo";
    }
}
